package com.itheima.controller;

import com.itheima.bean.vo.Code;
import com.itheima.bean.vo.Result;
import com.itheima.exception.BusinessException;
import com.itheima.exception.SystemException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ProjectExceptionAdvice {
    @ExceptionHandler(BusinessException.class)
    public Result doBussinessException(BusinessException ex) {
        return new Result(ex.getCode(), ex.getMessage());
    }

    @ExceptionHandler(SystemException.class)
    public Result doSystemException(SystemException ex) {
        return new Result(ex.getCode(), ex.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public Result doSystemException(Exception ex){
        return new Result(Code.EXCEPTION_ERR, ex.getMessage());
    }
}
